﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TRTCMain.Controls
{
    public partial class MicroButton : UserControl
    {
        private bool isChecked = true;
        public delegate void CheckStatusChangedHandler(bool isChecked);
        public event CheckStatusChangedHandler CheckStatusChanged;

        public delegate void BtnClickHandler();
        public event BtnClickHandler BtnClicked;

        public MicroButton()
        {
            InitializeComponent();
            IsChecked = true;
            this.Click += Label_Click;
            this.label.Click += Label_Click;
            this.pictureBox.Click += Label_Click;
            this.MouseMove += MicroButton_MouseMove; ;
            this.MouseLeave += MicroButton_MouseLeave; ;
            pictureBox.MouseMove += PictureBox_MouseMove; ;
            pictureBox.MouseLeave += PictureBox_MouseLeave; ;
            label.MouseMove += Label_MouseMove; ;
            label.MouseLeave += Label_MouseLeave; 
        }

        private void Label_MouseLeave(object sender, EventArgs e)
        {
            this.BackColor = Color.FromArgb(32, 34, 36);
        }

        private void Label_MouseMove(object sender, MouseEventArgs e)
        {
            this.BackColor = Color.FromArgb(69, 70, 72);
        }

        private void PictureBox_MouseLeave(object sender, EventArgs e)
        {
            this.BackColor = Color.FromArgb(32, 34, 36);
        }

        private void PictureBox_MouseMove(object sender, MouseEventArgs e)
        {
            this.BackColor = Color.FromArgb(69, 70, 72);
        }

        private void MicroButton_MouseLeave(object sender, EventArgs e)
        {
            this.BackColor = Color.FromArgb(32, 34, 36);
        }

        private void MicroButton_MouseMove(object sender, MouseEventArgs e)
        {
            this.BackColor = Color.FromArgb(69, 70, 72);
        }

        public bool IsChecked
        {
            get { return this.isChecked; }
            set
            {
                this.isChecked = value;
                ChangeStatus(value);
            }
        }

        private void ChangeStatus(bool isChecked)
        {
            if (IsChecked)
            {
                this.pictureBox.Image = Properties.Resources.icon_meeting_audio_mute_manager_2x__2_;
                this.label.ForeColor = Color.White;
                this.label.Text = "静音";
            }
            else
            {
                this.pictureBox.Image = Properties.Resources.icon_meeting_audio_mute_manager_2x;
                this.label.ForeColor = Color.White;
                this.label.Text = "解除静音";
               
            }

            CheckStatusChanged?.Invoke(IsChecked);
        }

        private void Label_Click(object sender, EventArgs e)
        {
            BtnClicked?.Invoke();
        }
    }
}
